package com.itany.thread.test01;

public class Ticket implements Runnable {
	private int count = 100;

	@Override
	public void run() {
		while(true){
			synchronized (this) {
				if(count > 0){
					try {
						Thread.sleep(10);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName()+"正在出票,票号为:"+count--);
				}
			}
		}
	}
	
//	@Override
//	public synchronized void run() {
//		while(count > 0){
//			try {
//				Thread.sleep(10);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//			System.out.println(Thread.currentThread().getName()+"正在出票,票号为:"+count--);
//		}
//	}

}
